﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Jalal.Library.Data;
using System.Data.Common;

namespace BCGC.DAL
{
    public class MarketPlaceData
    {
        public static DataTable GetAllMarketListing()
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetAllMarketPlaceData";
            return dataMiner.GetListData(command);
        }

        public static DataTable GetMarketByID(int id)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetMarketPlaceByID";
            dataMiner.AddParameter(command, "@ItemID", DbType.Int16, 0, ParameterDirection.Input, id);
            return dataMiner.GetListData(command);
        }

        public static bool UpdateMarket(int itemID, bool isActive, string adminComment, string marketContent, bool showContactInfo)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_UpdateMarketPlace";
            dataMiner.AddParameter(command, "@ItemID", DbType.Int16, 0, ParameterDirection.Input, itemID);
            dataMiner.AddParameter(command, "@IsActive", DbType.Boolean, 0, ParameterDirection.Input, isActive);
            dataMiner.AddParameter(command, "@AdminComment", DbType.String, 0, ParameterDirection.Input, adminComment);
            dataMiner.AddParameter(command, "@MarketContent", DbType.String, 0, ParameterDirection.Input, marketContent);
            dataMiner.AddParameter(command, "@ShowContactInfo", DbType.Boolean, 0, ParameterDirection.Input, showContactInfo);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);
            if (count == null)
                return false;
            else
                return (((int)count==0)?false:true);
            
        }
    }
}
